﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    Inherits="Pages_Reservation_Reservation" CodeBehind="Reservation.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="using" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="content" runat="Server">
    <div style="margin: 10px 3px 0 3px">
        <h1 style="text-indent: 10px">
            Reservation</h1>
        <div style="margin: 15px">
            <table>
                <%--<tr>
                    <td>
                        <div class="item">
                            <div class="label" style="color: Red;">
                                Departure date:</div>
                            <div class="field">
                                <asp:TextBox ID="txtDepartureDate" runat="server" CssClass="datepicker required"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="*"
                                    SetFocusOnError="true" ControlToValidate="txtDepartureDate"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </td>
                </tr>--%>
                <tr>
                    <td>
                        <div class="item">
                            <div class="label">
                                Board date:</div>
                            <div class="field">
                                <asp:TextBox ID="txtBoardDate" runat="server" CssClass="datepicker required"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
                                    SetFocusOnError="true" ControlToValidate="txtBoardDate"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="item">
                            <div class="label">
                                Boat:
                            </div>
                            <div class="field">
                                <asp:DropDownList ID="ddlBoat" runat="server" CssClass="Boat" AppendDataBoundItems="true">
                                    <asp:ListItem class="firstItem" Value="">Select a boat ...</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*"
                                    InitialValue="" ControlToValidate="ddlBoat"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="item">
                            <div class="label">
                                N&#186; of nights:
                            </div>
                            <div class="field">
                                <asp:DropDownList ID="ddlDateNumber" runat="server" CssClass="DateNumber">
                                    <asp:ListItem>1</asp:ListItem>
                                    <asp:ListItem>2</asp:ListItem>
                                    <asp:ListItem>3</asp:ListItem>
                                    <asp:ListItem>4</asp:ListItem>
                                    <asp:ListItem>5</asp:ListItem>
                                    <asp:ListItem>6</asp:ListItem>
                                    <asp:ListItem>7</asp:ListItem>
                                    <asp:ListItem>8</asp:ListItem>
                                    <asp:ListItem>9</asp:ListItem>
                                    <asp:ListItem>10</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
                                    InitialValue="" ControlToValidate="ddlDateNumber"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="item">
                            <div class="label">
                                N&#186; of cabins:
                            </div>
                            <div class="field">
                                <asp:DropDownList ID="ddlCabinNumber" runat="server" CssClass="CabinNumber">
                                    <asp:ListItem>1</asp:ListItem>
                                    <asp:ListItem>2</asp:ListItem>
                                    <asp:ListItem>3</asp:ListItem>
                                    <asp:ListItem>4</asp:ListItem>
                                    <asp:ListItem>5</asp:ListItem>
                                    <asp:ListItem>6</asp:ListItem>
                                    <asp:ListItem>7</asp:ListItem>
                                    <asp:ListItem>8</asp:ListItem>
                                    <asp:ListItem>9</asp:ListItem>
                                    <asp:ListItem>10</asp:ListItem>
                                    <asp:ListItem>11</asp:ListItem>
                                    <asp:ListItem>12</asp:ListItem>
                                    <asp:ListItem>13</asp:ListItem>
                                    <asp:ListItem>14</asp:ListItem>
                                    <asp:ListItem>15</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*"
                                    InitialValue="" ControlToValidate="ddlCabinNumber"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="item">
                            <div class="label">
                                Charter
                            </div>
                            <div class="field1">
                                <input type="checkbox" id="cbCharter" class="checkbox" />
                            </div>
                        </div>
                    </td>
                    <td align="center">
                        <a id="linksearch" title="Check cabins" class="button"><span>Check cabin</span></a>
                        <span class="result"></span><a class="createbooking button"><span class="result1"></span>
                        </a>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <script type="text/javascript">

        $(function () {

            // Datepicker
            $(".datepicker").datepicker({
                onSelect: function () { }
            });
        });
        $(document).ready(function () {

            $('a.createbooking').css("display", "none");

            var validControl = $([]).add($("#<%=txtBoardDate.ClientID %>"));

            function validation() {
                var b = true;
                var first = true;
                validControl.each(function () {
                    b &= $(this).valid();
                    if (!b && first) {
                        $(this).focus();
                        first = false;
                    }
                });
                if (!b) return false;

                return true;
            }

            $('#linksearch').click(function () {
                if (!validation()) return;

                CheckAvaiable();
            });
            function CheckAvaiable() {

                var datepicker = $("#<%=txtBoardDate.ClientID %>").val();
                var CabinNumber = $('.CabinNumber').val();
                var DateNumber = $('.DateNumber').val();
                var Charter = $('#cbCharter').is(':checked');
                var boatID = $('.Boat').val();

                var parameters = "{isCharter: " + Charter + ", boatID: '" + boatID + "', boardDateString: '" + datepicker + "', noOfNights:" + DateNumber + ", noOfCabins:" + CabinNumber + "}";

                $.ajax({
                    type: "POST",
                    url: "/Get.asmx/CheckCabinAvaliable",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: parameters,
                    success: function (msg) {
                        if (msg.d) {
                            var location = "/Pages/Reservations/ReservationAdd.aspx?BoatID=" + boatID + "&DepartureDate=" + datepicker + "&BoardDate=" + datepicker + "&NoOfCabins=" + CabinNumber + "&NoOfNights=" + DateNumber + "&IsCharter=" + Charter;

                            var createbooking = $('a.createbooking');
                            $('span.result1').text("Create Booking");
                            createbooking.attr("href", location).css("display", "block");
                            $('span.result').text("");
                        }
                        else {
                            $('span.result').text("Not available").css("font-size", "11pt").css("color", "red");
                            $('a.createbooking').css("display", "none");
                            $('span.result1').text("");
                        }
                        return false;
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        var err = eval("(" + XMLHttpRequest.responseText + ")");
                        alert("Please select the departure date and a boat to check free cabins. Details: " + err.Message);
                        return false;
                    }
                });
            }
        });
    </script>

</asp:Content>
